﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization;
using System.Windows;

namespace RecommendatioNetwork
{
    [DataContract]
    [Serializable]
    public class Search:EventArgs
    {
        [DataMember]
        public string Typology { get; set; }
        [DataMember]
        public string TextSearched { get; set; }
        [DataMember]
        private Uri uri;
        [DataMember]
        private uint timeToLive;
        [DataMember]
        private DateTime dateOfRequest;
        [DataMember]
        public string TypeOfSearch { get; set; }
        [DataMember]
        private DateTime dateOfExpiry;
        [DataMember]
        private TimeSpan periodOfValidateOfSearch;

        public Search(Model model)
        {
            this.timeToLive = model.MyConfiguration.TTL;
            this.uri = model.MyRepository.MyUri;
            this.dateOfRequest = DateTime.UtcNow;
            this.periodOfValidateOfSearch = model.MyConfiguration.PeriodOfValidateSerch;
            this.dateOfExpiry = dateOfRequest.Add(periodOfValidateOfSearch);
        }

        public Uri Uri {
            get { return uri; }
        }
        public uint TimeToLive {
            get { return timeToLive; }
            set {timeToLive=value;}
        }
        public DateTime DateOfRequest {
            get { return dateOfRequest; }
        }
        public string KeyRequest {
            get { return "AS"+Uri.ToString() + DateOfRequest+TextSearched;  }
        }
        public DateTime DateOfExpiry
        {
            get { return dateOfExpiry; }
        }
        public override bool Equals(object obj)
        {
            Search search = obj as Search;
            if (string.Equals(search.KeyRequest, this.KeyRequest, StringComparison.InvariantCultureIgnoreCase))
                return true;
            else return false;
        }
        public override int GetHashCode()
        {
            return base.GetHashCode();
        }      
    }
}
